﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_bid_goods_chexiao : System.Web.UI.Page
{
    //public Int32 PJID;
   

    protected void Page_Load(object sender, EventArgs e)
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
       
        if (_Account != null)
        {
            if (int.Parse(_Account.Type) == 1)
            {
                //PJID = 13; 
                showGrid();
            }
            else
            {
                Response.Write("<script>window.alert('对不起，请重新登录！');</script>");
                Response.Write("<script>window.location.href='../HomePage/Default.aspx';</script>");
            }

        }
        else
        {
            Response.Write("<script>window.alert('对不起，请重新登录！');</script>");
            Response.Write("<script>window.location.href='../HomePage/Default.aspx';</script>");
        }

    }
    protected void showGrid()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "v_product_goods as a inner join bid_Goods_TBR  as b on a.goodsid=b.goodsid  inner join bid_project_product d on a.productid=d.productid  ";                                               //要查询的表明
        //要查询的表明
        dbPage.Key = "a.goodsid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "a.goodsid,a.productname,a.Medicinemodel,a.Outlookc,a.Unit,a.xishu,a.usercode as usercode_SC,b.usercode_tb,b.username_tb, a.companyname as username_SC,b.Accept_time, case status when 0 then '未确认' when 1 then '已确认'  when 2 then '已撤销' else '未设置' end as status";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 15;                                                    //没有显示记录条数   
        dbPage.OrderBy = "a.goodsid,Productname";        //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    public string fctConditions()
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        string strwhere = "  b.projectid= 13 and status=1";
        string txtgoodsid = "";//流水号
        txtgoodsid = Textgoodsid.Text.ToString().Trim();
        string txtcompanyname = "";//生产企业
        txtcompanyname = comoanyname_sc.Text.ToString().Trim();
        string txtusercode = "";//生产企业用户名
        txtusercode = usercode.Text.ToString().Trim();
        string usercode_tb = "";//投标企业用户名
        usercode_tb=TextusercodeTB.Text.ToString().Trim();
        string company_tb = "";
        company_tb = Textcompanytb.Text.ToString().Trim();
        if (txtgoodsid != "")
        {
            strwhere += " and a.goodsid=" + txtgoodsid;
        }
        if (txtcompanyname != "")
        {
            strwhere += " and a.companyname like'%" + txtcompanyname + "%'";
        }
        if (txtusercode != "")
        {
            strwhere += " and a.usercode like '%" + txtusercode+"%'";
        }

        if (usercode_tb != "")
        {
            strwhere += " and b.usercode_tb like '%" + usercode_tb + "%'";
        }
        if (company_tb != "")
        {
            strwhere += " and b.username_tb like '%" + company_tb + "%'";
        }
        return strwhere;

    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        SetStatus(2);//撤销
    }

    protected void SetStatus(int status)
    {
        //string strSql = "";
        string goodsid = "";
        goodsid = SysFun.ToTrim(Request.Form["chk"]);

        //bool succ = false;
        Db db = new Db();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (goodsid != "")
        {
           string strSql = "";
           string strSql1 = "";

           strSql = "update bid_goods_tbr set status=0 ,accountid_tb=null,usercode_tb=null,username_tb=null, Accept_time =getdate() where goodsid in (" + goodsid + ") and  projectid=13";
            strSql1 = "delete from  Project_Bid where  goodsid in (" + goodsid + ") ";
            db.Command(strSql);
            db.Command(strSql1);
                //succ = db.ExecuteTransaction(strSql.Substring(1).Split(new char[] { '@' }), 30);
             //   HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "投标人确认/撤销" + status.ToString(), "bid_goods_tbr", strSql, "../Bidder/Acceptbidder.aspx");
            
        }

        //if (succ)
        //{
        Response.Write("<script>alert('状态更新成功'</script>");//;window.opener.location.reload();window.close();</script>");
        //}
        //else
        //{
        //    Response.Write("<script>alert('操作失败,请确认您是否已经执行!');window.opener.location.reload();</script>");
        //}

        db.Close();

        showGrid();

    }
    protected void ToEcxul_Click(object sender, EventArgs e)
    {
        Db db = new Db();
        System.Data.IDataReader dr;
        string _strSql = "Select a.goodsid as 商品流水号,a.productname as 通用名,a.Medicinemodel as 剂型,a.Outlookc as 规格,a.Unit as 单位,a.xishu as 转换系数,a.usercode as 生产企业用户名,a.companyname as 生产企业名称,b.usercode_tb as 投标企业用户名,b.username_tb as 投标企业名称,  case status when 0 then '未确认' when 1 then '已确认'  when 2 then '已撤销' else '未设置' end as status,b.Accept_time 操作日期 From v_product_goods as a inner join bid_Goods_TBR  as b on a.goodsid=b.goodsid  inner join bid_project_product d on a.productid=d.productid   Where   b.projectid= 13 and status=1 order by a.goodsid";
        dr = db.DataReader(_strSql);
        GridView2.DataSource = dr;
        GridView2.DataBind();
        db.Close();
        dr.Close();
        dr.Dispose();
        string filename = System.Web.HttpUtility.UrlEncode("导出数据.xls");
        SysFun.WriteToExcel(GridView2, this.Page, filename);


    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        //OverRide　为了使导出成Excel可行！

    }
}
